
// IR_Send.c
// Sylvia Carrell
// Senior Design 1

#include <delays.h>
#include <p18F26K80.h>

#define IRLED PORTCbits.RC2

unsigned char LEVEL,p,in,temp, k;

void IR_Send(int type);
void signal_on(unsigned long a);
void signal_off(unsigned long b);
void IR_Damage(void);
void IR_Heal(void);
void IR_Venom(void);
void IR_PowerUp(void);


void IR_Send(int type)
{
    Delay10KTCYx(40);
    switch(type)
    {
        case 1: //Heal
            Delay1TCY();
            for(in=0;in<2;in++){
                Delay10KTCYx(20);
                IR_Heal();
            }
            break;
        case 2: //Power Up
            Delay1TCY();
            for(in=0;in<2;in++){
                Delay10KTCYx(20);
                IR_PowerUp();
            }
            break;
        case 3: //Envenom
            Delay1TCY();
            for(in=0;in<2;in++){
                Delay10KTCYx(20);
                IR_Venom();
            }
            break;
         case 4: //Damage!
            Delay1TCY();
            for(in=0;in<2;in++){
                Delay10KTCYx(20);
                IR_Damage();
            }
            break;
    }
}

void signal_on(unsigned long a){
    for (k=0;k<=a;k++){
        IRLED = 1;
        Delay10TCYx (2);
        Delay1TCY();
        Delay1TCY();
        
        IRLED = 0;
        Delay10TCYx (2);
        Delay1TCY();
        Delay1TCY();
        
    }
}

void signal_off(unsigned long b){
    for (k=0;k<=b;k++){
        IRLED = 1;
        Delay10TCYx (2);
        Delay1TCY();
        Delay1TCY();
        IRLED = 1;
        Delay10TCYx (2);
        Delay1TCY();
        Delay1TCY();
    }
}

void IR_Damage(void){
    //TQ1
    signal_on(10);
    signal_off(140);
    //TQ2
    signal_on(20);
    signal_off(130);
    //TQ3 (redundant)
    signal_on(20);
    signal_off(130);
    //TQ4
    signal_on(150);

}

void IR_Heal(void){
    //TQ1
    signal_on(10);
    signal_off(140);
    //TQ2
    signal_on(30);
    signal_off(120);
    //TQ3 (redundant)
    signal_on(30);
    signal_off(120);
    //TQ4
    signal_on(150);
}

void IR_Venom(void){
    //TQ1
    signal_on(10);
    signal_off(140);
    //TQ2
    signal_on(40);
    signal_off(110);
    //TQ3 (redundant)
    signal_on(40);
    signal_off(110);
    //TQ4
    signal_on(150);
}

void IR_PowerUp(void){
    //TQ1
    signal_on(10);
    signal_off(140);
    //TQ2
    signal_on(50);
    signal_off(100);
    //TQ3 (redundant)
    signal_on(50);
    signal_off(100);
    //TQ4
    signal_on(150);
}
